﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using MySql.Data.MySqlClient;
using Test;

namespace vacabulary
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private int index = 1;
        MySqlConnection connection;
        public MainWindow()
        {
            connection = Utils.connect();
            InitializeComponent();
            english.KeyUp += new KeyEventHandler(english_TextChanged);
            var list = Utils.getPair(this.index, connection);
            chinese.Text = list.ToList()[0];
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (index == 1) return;
            index -= 1;
            var list = Utils.getPair(this.index, connection);
            chinese.Text = list.ToList()[0];
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            if (index == Utils.getMaxID(connection)) return;
            index += 1;
            var list = Utils.getPair(this.index, connection);
            chinese.Text = list.ToList()[0];
        }

        private void english_TextChanged(object sender, KeyEventArgs e)
        {

            if (e.Key == Key.Enter)
            {
                var list = Utils.getPair(this.index, connection);
                if (list.ToList()[1] == english.Text)
                {
                    output.Text = "True";
                }
                else
                {
                    output.Text = "False";
                }
            }

        }
    }
}
